<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- 
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License. 
-->
<html>
<head>
    <link type="text/css" rel="stylesheet" href="https://struts.apache.org/css/default.css">
    <style type="text/css">
        .dp-highlighter {
            width:95% !important;
        }
    </style>
    <style type="text/css">
        .footer {
            background-image:      url('https://cwiki.apache.org/confluence/images/border/border_bottom.gif');
            background-repeat:     repeat-x;
            background-position:   left top;
            padding-top:           4px;
            color:                 #666;
        }
    </style>
    <link href='https://struts.apache.org/highlighter/style/shCoreStruts.css' rel='stylesheet' type='text/css' />
    <link href='https://struts.apache.org/highlighter/style/shThemeStruts.css' rel='stylesheet' type='text/css' />
    <script src='https://struts.apache.org/highlighter/js/shCore.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushPlain.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushXml.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushJava.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushJScript.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushGroovy.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushBash.js' type='text/javascript'></script>
    <script type="text/javascript">
        SyntaxHighlighter.defaults['toolbar'] = false;
        SyntaxHighlighter.all();
    </script>
    <script type="text/javascript" language="javascript">
        var hide = null;
        var show = null;
        var children = null;

        function init() {
            /* Search form initialization */
            var form = document.forms['search'];
            if (form != null) {
                form.elements['domains'].value = location.hostname;
                form.elements['sitesearch'].value = location.hostname;
            }

            /* Children initialization */
            hide = document.getElementById('hide');
            show = document.getElementById('show');
            children = document.all != null ?
                    document.all['children'] :
                    document.getElementById('children');
            if (children != null) {
                children.style.display = 'none';
                show.style.display = 'inline';
                hide.style.display = 'none';
            }
        }

        function showChildren() {
            children.style.display = 'block';
            show.style.display = 'none';
            hide.style.display = 'inline';
        }

        function hideChildren() {
            children.style.display = 'none';
            show.style.display = 'inline';
            hide.style.display = 'none';
        }
    </script>
    <title>web.xml</title>
</head>
<body onload="init()">
<table border="0" cellpadding="2" cellspacing="0" width="100%">
    <tr class="topBar">
        <td align="left" valign="middle" class="topBarDiv" align="left" nowrap>
            &nbsp;<a href="home.html">Home</a>&nbsp;&gt;&nbsp;<a href="guides.html">Guides</a>&nbsp;&gt;&nbsp;<a href="core-developers-guide.html">Core Developers Guide</a>&nbsp;&gt;&nbsp;<a href="configuration-files.html">Configuration Files</a>&nbsp;&gt;&nbsp;<a href="webxml.html">web.xml</a>
        </td>
        <td align="right" valign="middle" nowrap>
            <form name="search" action="https://www.google.com/search" method="get">
                <input type="hidden" name="ie" value="UTF-8" />
                <input type="hidden" name="oe" value="UTF-8" />
                <input type="hidden" name="domains" value="" />
                <input type="hidden" name="sitesearch" value="" />
                <input type="text" name="q" maxlength="255" value="" />
                <input type="submit" name="btnG" value="Google Search" />
            </form>
        </td>
    </tr>
</table>

<div id="PageContent">
    <div class="pageheader" style="padding: 6px 0px 0px 0px;">
        <!-- We'll enable this once we figure out how to access (and save) the logo resource -->
        <!--img src="/wiki/images/confluence_logo.gif" style="float: left; margin: 4px 4px 4px 10px;" border="0"-->
        <div style="margin: 0px 10px 0px 10px" class="smalltext">Apache Struts 2 Documentation</div>
        <div style="margin: 0px 10px 8px 10px"  class="pagetitle">web.xml</div>

        <div class="greynavbar" align="right" style="padding: 2px 10px; margin: 0px;">
            <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=14316">
                <img src="https://cwiki.apache.org/confluence/images/icons/notep_16.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Edit Page"></a>
            <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=14316">Edit Page</a>
            &nbsp;
            <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">
                <img src="https://cwiki.apache.org/confluence/images/icons/browse_space.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Browse Space"></a>
            <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">Browse Space</a>
            &nbsp;
            <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=14316">
                <img src="https://cwiki.apache.org/confluence/images/icons/add_page_16.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Add Page"></a>
            <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=14316">Add Page</a>
            &nbsp;
            <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=14316">
                <img src="https://cwiki.apache.org/confluence/images/icons/add_blogentry_16.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Add News"></a>
            <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=14316">Add News</a>
        </div>
    </div>

    <div class="pagecontent">
        <div class="wiki-content">
            <div id="ConfluenceContent"><p>The <code>web.xml</code> web application descriptor file represents the core of the Java web application, so it is appropriate that it is also part of the core of the Struts framework.  In the <code>web.xml</code> file, Struts defines its FilterDispatcher, the Servlet Filter class that initializes the Struts framework and handles all requests.  This filter can contain initialization parameters that affect what, if any, additional configuration files are loaded and how the framework should behave.</p>

<p>In addition to the FilterDispatcher, Struts also provides an ActionContextCleanUp class that handles special cleanup tasks when other filters, such as those used by Sitemesh, need access to an initialized Struts framework.</p>

<h2 id="web.xml-KeyInitializationParameters">Key Initialization Parameters</h2>

<p></p><p></p>
<ul></ul><p></p>
<ul><li><b>config</b> - a comma-delimited list of XML configuration files to load.</li></ul><p></p>
<ul><li><b>actionPackages</b> - a comma-delimited list of Java packages to scan for Actions.</li></ul><p></p>
<ul><li><b>configProviders</b> - a comma-delimited list of Java classes that implement the
ConfigurationProvider interface that should be used for building the Configuration.</li></ul><p></p>
<ul><li><b>loggerFactory</b> - The class name of the LoggerFactory implementation.</li></ul><p></p>
<ul><li><b>*</b> - any other parameters are treated as framework constants.</li></ul><p></p>

<p></p>

<h2 id="web.xml-SimpleExample">Simple Example</h2>

<p>Configuring <code>web.xml</code> for the framework is a matter of adding a filter and filter-mapping.</p>

<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>FilterDispatcher Example (web.xml)</b></div><div class="codeContent panelContent pdl">
<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[
&lt;web-app id=&quot;WebApp_9&quot; version=&quot;2.4&quot; 
	xmlns=&quot;http://java.sun.com/xml/ns/j2ee&quot; 
	xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; 
	xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd&quot;&gt;

    &lt;filter&gt;
        &lt;filter-name&gt;struts2&lt;/filter-name&gt;
        &lt;filter-class&gt;org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter&lt;/filter-class&gt;
        &lt;init-param&gt;
        	&lt;param-name&gt;actionPackages&lt;/param-name&gt;
        	&lt;param-value&gt;com.mycompany.myapp.actions&lt;/param-value&gt;
        &lt;/init-param&gt;
    &lt;/filter&gt;

    &lt;filter-mapping&gt;
        &lt;filter-name&gt;struts2&lt;/filter-name&gt;
        &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
    &lt;/filter-mapping&gt;

    &lt;!-- ... --&gt;

&lt;/web-app&gt;
]]></script>
</div></div>

    <div class="aui-message warning shadowed information-macro">
                    <p class="title">Changed Filter Structure in Struts &gt;= 2.1.3</p>
                            <span class="aui-icon icon-warning">Icon</span>
                <div class="message-content">
                            
<p>To split up the the dispatcher phases, FilterDispatcher is deprecated since Struts 2.1.3. If working with older versions, you need to use</p>
<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[
    ...
    &lt;filter&gt;
        &lt;filter-name&gt;struts2&lt;/filter-name&gt;
        &lt;filter-class&gt;org.apache.struts2.dispatcher.FilterDispatcher&lt;/filter-class&gt;
    ...
]]></script>
</div></div>
<p>See <a shape="rect" href="sitemesh-plugin.html">SiteMesh Plugin</a> for an example on when to use seperate Filters for prepare and execution phase</p>
                    </div>
    </div>


    <div class="aui-message warning shadowed information-macro">
                    <p class="title">Why the Filter is mapped with /* and how to configure explicit exclusions (since 2.1.7)</p>
                            <span class="aui-icon icon-warning">Icon</span>
                <div class="message-content">
                            
<p>  In the example above we've mapped the Struts 2 dispatcher to <code>/*</code>, so Struts 2 has a crack at all incoming requests. This is because Struts 2 serves static content from its jar files, including Dojo JavaScript files (if using S2.0, or the Dojo plugin in S2.1+) and FreeMarker templates for the Struts 2 tags that produce HTML.</p>

<p>  If we change the filter mapping to something else, for example <code>/*.html</code>, we must take this in to account and extract the content that would normally be served from the Struts 2 jar files, or some other solution.</p>

<p>  Since Struts 2.1.7, you are able to provide a comma seperated list of patterns for which when matching against the<br clear="none">
request URL the Filter will just pass by. This is done via the configuration option struts.action.excludePattern, for example in your struts.xml</p>
<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[
&lt;struts&gt;
    &lt;constant name=&quot;struts.action.excludePattern&quot; value=&quot;.*unfiltered.*,.*\\.nofilter&quot;/&gt;
    ...

&lt;/struts&gt;
]]></script>
</div></div>
                    </div>
    </div>


<h2 id="web.xml-TaglibExample">Taglib Example </h2>

<p>Typically, configuring a taglib is neither required nor recommended. The taglib is included in <code>struts-core.jar</code>, and the container will discover it automatically.</p>

<p><img class="emoticon emoticon-tick" src="https://cwiki.apache.org/confluence/s/en_GB-1988229788/4109/76e0dbb30bc8580e459c201f3535d84f9283a9ac.1/_/images/icons/emoticons/check.png" data-emoticon-name="tick" alt="(tick)">  If, for some reason, a taglib configuration is needed within web.xml, extract the TLD file from the <code>struts-core.jar</code> <code>META-INF</code> folder, and add a <code>taglib</code> element to the <code>web.xml</code>.</p>

<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[
    &lt;!-- ... --&gt;
    &lt;/welcome-file-list&gt;

    &lt;taglib&gt;
       &lt;taglib-uri&gt;/s&lt;/taglib-uri&gt;
       &lt;taglib-location&gt;/WEB-INF/struts-tags.tld&lt;/taglib-location&gt;
    &lt;/taglib&gt;
&lt;/web-app&gt;
]]></script>
</div></div>

<h2 id="web.xml-CustomFileManagerandFileManagerFactoryimplementations">Custom FileManager and FileManagerFactory implementations</h2>

<p>If there is a need to support an App Server's specific file system (eg. VFS in JBoss), you can implement your own version of FileManager. But it must be registered at "the beginning" to support bootstrap of the whole framework.</p>

<p>To register your own FileManger you can do it with &lt;init-param/&gt; as below:</p>

<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[
&lt;filter&gt;
     &lt;filter-name&gt;struts2&lt;/filter-name&gt;
     &lt;filter-class&gt;org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter&lt;/filter-class&gt;
     &lt;init-param&gt;
         &lt;param-name&gt;struts.fileManager&lt;/param-name&gt;
         &lt;param-value&gt;com.company.MyFileManager&lt;/param-value&gt;
     &lt;/init-param&gt;
&lt;/filter&gt;
]]></script>
</div></div>

<p>You can as well register your own FileManagerFactory with &lt;init-param/&gt;, see example:</p>

<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[
&lt;filter&gt;
     &lt;filter-name&gt;struts2&lt;/filter-name&gt;
     &lt;filter-class&gt;org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter&lt;/filter-class&gt;
     &lt;init-param&gt;
         &lt;param-name&gt;struts.fileManagerFactory&lt;/param-name&gt;
         &lt;param-value&gt;com.company.MyFileManagerFactory&lt;/param-value&gt;
     &lt;/init-param&gt;
&lt;/filter&gt;
]]></script>
</div></div>

<p>Take a look on default implementations - DefaultFileManager.java and DefaultFileManagerFactory.java to understand how and why.</p></div>
        </div>

        
    </div>
</div>
<div class="footer">
    Generated by CXF SiteExporter
</div>
</body>
</html>
